package sorted;

import java.util.Arrays;

public class S02_SelectionSort {
    public static void main(String[] args) {
        int[] arr = {5,7,2,3,4,1,6,18,9,10,16,56,34,23,11,12,31,17,15};
        selectionSort(arr);

        System.out.println("排序后的数组为："+ Arrays.toString(arr));
    }

    public static int[] selectionSort(int[] arr) {
        int length = arr.length;
        for (int i = 0; i < length; i++) {
            int min = i;

            for (int j = i+1; j < length; j++) {
                if (arr[min] > arr[j]) min=j;
            }

            int temp = arr[i];
            arr[i] = arr[min];
            arr[min] = temp;
        }

        return arr;
    }
}
